export default {
    props: {
        _input: {
            required: true,
        },
    },
    data() {
        // @VExportData-Start
        return {
            master: {
                owner_id: null,
                dates: null,
                asn_start_time: null,
                asn_end_time: null,
                biz_code: null,
                order_type: null,
                order_biz_type: null,
                remark: null,
            },
            grid1: {
                isChanged: false,
                selections: [],
                checkedRows: [],
                selection: null,
            },
            vjson: {
                layout: 'SimpleGrid',
                toolbar: {
                    xtype: 'toolbar',
                    items: [
                        {
                            xtype: 'button',
                            iconCls: 'antd CheckCircleFilled',
                            text: '进入流程',
                            type: 'primary',
                            plain: true,
                            listeners: {
                                click: '{button2_click}',
                            },
                        },
                        {
                            xtype: 'button',
                            iconCls: 'fa Boxes',
                            text: '批量生成库存',
                            type: 'primary',
                            plain: true,
                            listeners: {
                                click: '{button1_click}',
                            },
                            bind: {
                                disabled: '{button1_disabled}',
                            },
                        },
                    ],
                },
                form: [
                    {
                        xtype: 'form',
                        colsOfRow: '4',
                        items: [
                            {
                                xtype: 'combo',
                                fieldLabel: '货主',
                                bind: {
                                    value: '{master.owner_id}',
                                },
                                dataType: 2,
                                dataDict: 'OWNER',
                                required: true,
                            },
                            {
                                xtype: 'datefield',
                                type: 'date',
                                fieldLabel: '日期',
                                bind: {
                                    value: '{master.dates}',
                                },
                                readonly: true,
                            },
                            {
                                xtype: 'datefield',
                                type: 'date',
                                fieldLabel: '到货开始时间',
                                bind: {
                                    value: '{master.asn_start_time}',
                                },
                            },
                            {
                                xtype: 'datefield',
                                type: 'date',
                                fieldLabel: '到货截至时间',
                                bind: {
                                    value: '{master.asn_end_time}',
                                },
                            },
                            {
                                xtype: 'textfield',
                                fieldLabel: '业务单号',
                                bind: {
                                    value: '{master.biz_code}',
                                },
                                required: true,
                            },
                            {
                                xtype: 'combo',
                                fieldLabel: '订单类型',
                                bind: {
                                    value: '{master.order_type}',
                                },
                                dataType: 2,
                                dataDict: 'taskType',
                                required: true,
                            },
                            {
                                xtype: 'combo',
                                fieldLabel: '业务订单类型',
                                bind: {
                                    value: '{master.order_biz_type}',
                                },
                                dataType: 2,
                                dataDict: 'ASN_TYPE',
                                required: true,
                            },
                            {
                                xtype: 'textfield',
                                fieldLabel: '备注',
                                bind: {
                                    value: '{master.remark}',
                                },
                                weight: 2,
                            },
                        ],
                        labelWidth: '',
                        reference: 'master',
                    },
                ],
                items: [
                    {
                        xtype: 'toolbar',
                        items: [
                            {
                                xtype: 'button',
                                text: '添加',
                                iconCls: 'antd PlusCircleFilled',
                                plain: true,
                                type: 'primary',
                                bind: {
                                    disabled: '{button3_disabled}',
                                },
                                listeners: {
                                    click: '{button3_click}',
                                },
                            },
                            {
                                xtype: 'button',
                                text: '编辑',
                                iconCls: 'element Edit',
                                bind: {
                                    disabled: '{button4_disabled}',
                                },
                            },
                            {
                                xtype: 'button',
                                text: '删除',
                                iconCls: 'element Delete',
                                type: 'danger',
                                plain: true,
                                bind: {
                                    disabled: '{button5_disabled}',
                                },
                                listeners: {
                                    click: '{button5_click}',
                                },
                            },
                        ],
                    },
                    {
                        xtype: 'aggrid',
                        reference: 'grid1',
                        pagination: true,
                        _mode: 'select',
                        pageSize: 100,
                        plugins: {
                            gridcellediting: {
                                selectOnEdit: true,
                            },
                        },
                        dataSource: {
                            method: 'invoke',
                            url: '/bas/item/Item@queryAllItem',
                            params: {
                                formData: {
                                    owner_id: '',
                                },
                            },
                        },
                        columns: [
                            {
                                dataIndex: 'item_id',
                                header: '商品主键',
                                hidden: false,
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'owner_id',
                                header: '货主ID',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'item_code',
                                header: '商品编码',
                                filterType: 'string',
                                editable: false,
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'item_name',
                                header: '商品名称',
                                filterType: 'string',
                                editable: false,
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'pack_id',
                                header: '包装',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'pack_name',
                                header: '包装名称',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'order_qty',
                                header: '预期到货数量',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot_id',
                                header: '批次ID',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot01',
                                header: '批属性01',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot02',
                                header: '批属性02',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot03',
                                header: '批属性03',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot04',
                                header: '批属性04',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot05',
                                header: '批属性05',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot06',
                                header: '批属性06',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot07',
                                header: '批属性07',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot08',
                                header: '批属性08',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot09',
                                header: '批属性09',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot10',
                                header: '批属性10',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot11',
                                header: '批属性11',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                            {
                                dataIndex: 'lot12',
                                header: '批属性12',
                                filterType: 'string',
                                xtype: 'aggridcolumn',
                            },
                        ],
                        heightMode: 'fit',
                    },
                ],
                isFlex: true,
                height: '500px',
                listeners: {
                    onMounted: '{onMounted}',
                },
                title: '预期到货通知单',
            },
        }
        //@VExportData-End

    },
    methods: {
        onMounted() {
            this.master.dates = system.getNowDate()
        },
        button2_click() {
            const cl = system.showLoadingIfButton()
            this.refs.master.validate().then(res => {
                // 校验提交
                system.invokeServer('/pages/inbound/asn_in/AsnIn@commitAsn', {
                    master: this.master,
                    details: this.refs.grid1.getDataRows()
                }).then(res => {
                    system.msg(res.msg)

                }).finally(() => {
                    cl()
                })

            }).catch(() => {
                cl()
            })
        },
        button1_click() {
            const cl = system.showLoadingIfButton()
            // 校验提交
            system.invokeServer('/pages/inbound/asn_in/AsnIn@batchAddInv', {
                master: this.master
            }).then(res => {
                system.msg(res.data)
            }).finally(() => {
                cl()
            })
        },
        button3_click() {
            system.showDialog('/inbound/asn_in/AsnInItem.vue', {
                width: '750px',
                owner_id: this.master.owner_id,
                appendRow: (res) => {
                    const row = {
                        owner_id: this.master.owner_id,
                        ...res.row
                    }
                    this.refs.grid1.appendEditRow(row)
                }

            }).finally()
        },
        button5_click() {
            this.refs.grid1.removeSelectedRow()
        },
    },
    computed: {
        button1_disabled() {
            return !this.master.owner_id
        },
        button3_disabled() {
            return !this.master.owner_id
        },
        button4_disabled() {
            return !this.grid1.selection
        },
        button5_disabled() {
            return !this.grid1.selection
        },
    },
    watch: {},
}
